package com.sdp.right.excel.importExcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

public class RowCountListener extends AnalysisEventListener<Object> {
    private int totalRows = 0;
    private int dataStartRowIndex;

    public RowCountListener(int dataStartRowIndex) {
        this.dataStartRowIndex = dataStartRowIndex;
    }

    @Override
    public void invoke(Object rowData, AnalysisContext context) {
        int currentRowIndex = context.readRowHolder().getRowIndex();
        // 跳过标题之前的行
        if (currentRowIndex < dataStartRowIndex) {
            return;
        }

        totalRows++;
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        // 可在此处处理最终统计
    }

    public int getTotalRows() {
        return totalRows;
    }
}